#!/usr/bin/env python
# encoding: utf-8
'''
@author: zhaowenpeng
@contact: winston@peipeiyun.com
@software: garner
@file: __init__.py.py
@time: 2020/8/10 6:25 下午
@desc:
'''
class CustomException(Exception):
    """ 自定义异常 """

    def __init__(self, code=None, message=None):
        self.code = code
        self.message = message

    @property
    def info(self):
        if self.message is not None:
            return self.message

        attr = 'error_{code}'.format(code=self.code)
        if hasattr(self, attr):
            return self.__getattribute__(attr)
        else:
            return '未知异常'

class BadRequest(CustomException):
    status_code = 400
    message = "Bad Request"

class Unauthorized(CustomException):
    status_code = 401
    message = "Unauthorized"

class Forbidden(CustomException):
    status_code = 403
    message = "Not Found"

# class NotFound(CustomException):
#     status_code = 404
#     message = "Not Found"

class NotAcceptable(CustomException):
    status_code = 406
    message = "Unauthorized"

class Gone(CustomException):
    status_code = 410
    message = "Unauthorized"

class Enhance(CustomException):
    status_code = 420
    message = "Enhance Your Calm"

class UnprocessableEntity(CustomException):
    status_code = 422
    message = "Unprocessable Entity"

class TooManyRequests(CustomException):
    status_code = 429
    message = "Too Many Requests"

class ServerError(CustomException):
    status_code = 500
    message = "Internal Server Error"

class BadGateway(CustomException):
    status_code = 502
    message = "Bad Gateway"

class ServiceUnavailable(CustomException):
    status_code = 503
    message = "Service Unavailable"

class GatewayTimeout(CustomException):
    status_code = 504
    message = "Gatewa timeout"




